//
//  UrlSettingViewController.m
//  EducationAdminClient
//
//  Created by 周佳兴 on 2016/11/6.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "UrlSettingViewController.h"

@interface UrlSettingViewController ()<UITextFieldDelegate>
@property (strong, nonatomic)UITextField *programUrl;
@property (strong, nonatomic)UITextField *port;
@end

@implementation UrlSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createNav];
    
    
}


-(void)createNav{
    UIImageView*navImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 64)];
    navImageView.image=[UIImage imageNamed:@"qrcode_scan_bar.png"];
    navImageView.userInteractionEnabled=YES;
    [self.view addSubview:navImageView];
    UILabel*titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(320/2-32,20 , 64, 44)];
    titleLabel.textColor=[UIColor whiteColor];
    titleLabel.text=@"设置地址";
    [navImageView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(navImageView.mas_centerX).offset(+8);
        make.centerY.equalTo(navImageView.mas_centerY).offset(+5);
        make.width.equalTo(@(100));
        make.height.equalTo(@(44));
    }];
    [navImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.equalTo(self.view.mas_width);
        make.height.equalTo(@(64));
    }];
    
    _programUrl = [[UITextField alloc]init];
    
    _programUrl.text = getBase();
    
    _programUrl.layer.borderColor = [[UIColor redColor]CGColor];
    _programUrl.layer.borderWidth = 2;
    _programUrl.textAlignment = NSTextAlignmentCenter;
    _programUrl.delegate = self;
    [self.view addSubview:_programUrl];
    [_programUrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(20));
        make.top.equalTo(navImageView.mas_bottom).offset(20);
        make.right.equalTo(self.view.mas_right).offset(-20);
        make.height.equalTo(@(40));
    }];
    

    UIButton *btnsub = [[UIButton alloc]init];
    [self.view addSubview:btnsub];
    
    [btnsub mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(20));
        make.top.equalTo(_programUrl.mas_bottom).offset(50);
        make.right.equalTo(self.view.mas_right).offset(-20);
        make.height.equalTo(@(50));
    }];

    [btnsub addTarget:self action:@selector(btnsubcllllick) forControlEvents:UIControlEventTouchUpInside];
    [btnsub setTitle:@"保存" forState:UIControlStateNormal];
    btnsub.backgroundColor = [UIColor redColor];
}



-(void)btnsubcllllick{
    
    if(_programUrl.text.length>10){
        [self saveUrl:_programUrl.text];
        
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }else{
        [self showLabelWithText:@"请输入正确网址"];
    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    
    saveBaseUrl(textField.text);
    return YES;
}

-(void)saveUrl:(NSString *)string{
    saveBaseUrl(string);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
